﻿<link href="/Style%20Library/faq.css" rel="stylesheet" media="screen, projection" type="text/css" />
    <script type="text/javascript" src="/SiteCollectionDocuments/jquery.min.js"></script>

    <script type="text/javascript" src="/SiteCollectionDocuments/jquery.SPServices-0.5.4.min.js"></script>

    <script type="text/javascript" src="/SiteCollectionDocuments/SPSearch_load.js"></script> 

       <script type="text/javascript">

        function AddItems() {
            //create a array of submitted fields
            var fields = new Array;
            //retrieve section order nr

            KbWorks.lists.weburl = "http://devKbWorks/";
            KbWorks.lists.divname = "addItems";
            KbWorks.lists.elementtofill = "Sectionid";
            KbWorks.lists.viewfields = new Array;
            KbWorks.lists.viewfields[0] = ["SectionOrder", "SectionOrder"];
            KbWorks.lists.WithoutFilters = false;
            KbWorks.lists.Getvalue = true;
            KbWorks.filterfunctions.filters = null;
            KbWorks.filterfunctions.filteradd("Section", "Text", "Section", "Contains", document.getElementById("Category").value);
            KbWorks.lists.searchitems("FAQ");
            //retrieve sectionorder
            //alert(document.getElementById("Sectionid").value);

            KbWorks.lists.elementtofill = "questionid";
            KbWorks.lists.viewfields = new Array;
            KbWorks.lists.viewfields[0] = ["QuestionOrder", "QuestionOrder"];
            KbWorks.lists.WithoutFilters = false;
            KbWorks.lists.Getvalue = true;
            KbWorks.filterfunctions.filters = null;
            KbWorks.filterfunctions.filteradd("Section", "Text", "Section", "Contains", document.getElementById("Category").value);
            KbWorks.lists.searchitems("FAQ");
            //retrieve questionorder
            var highestnumber = document.getElementById("questionid").value;
            highestnumber=parseInt(highestnumber) + 1;
            document.getElementById("questionid").value = highestnumber ;
            // elt =
            fields[0] = ["Title", document.getElementById("Question").value, "Text"];
            fields[1] = ["Answer", document.getElementById("Answer").value, "Text"];
            //fields[2] = ["Section", 1, "Lookup"];
            fields[2] = ["Section", document.getElementById("Category").value, "Lookup"];
            fields[3] = ["SectionOrder", document.getElementById("Sectionid").value, "Text"];
            fields[4] = ["QuestionOrder", document.getElementById("questionid").value, "Text"];


            //submit fields to list
            //Fields
            //url to webservice
            //list
                       KbWorks.lists.insertitem(fields, "http://devKbWorks", "FAQ");
                        //generate ID
                      
                        //return ID to submitter.
                      var elt = document.getElementById("addItems");
            //            fields = new Array;
            //            fields[0] = ["ID", KbWorks.lists.returnedID, "Number"];
            //            fields[1] = ["Title", "KbWorksEC-" + KbWorks.lists.returnedID + " " + document.getElementById("Name").value, "Text"];
            //            KbWorks.lists.insertitem(fields, "http://devKbWorks/HR/insert/", "Changes");
                        KbWorks.UI.responsetext(elt, "Thank you for adding your Q and A to our portal");

        }
        $(document).ready(function() {
            KbWorks.lists.weburl = "http://devKbWorks/";
            KbWorks.lists.divname = "addItems";
            KbWorks.lists.elementtofill = "Category";
            KbWorks.lists.viewfields = new Array;
            KbWorks.lists.viewfields[0] = ["Section", "Section"];
            KbWorks.lists.WithoutFilters = false;
            KbWorks.lists.searchbox = true;
            KbWorks.filterfunctions.filteradd("QuestionOrder", "Text", "QuestionOrder", "Contains", "1");
            KbWorks.lists.searchitems("FAQ");




        });
        
    </script>

    <div id="addItems">
        <table>
            <tbody>
                <tr style="display:none;">
                    <td>
                        <input id="Sectionid" />
                    </td>
                    <td>
                        <input id="questionid" />
                    </td>
                </tr>
               
                <tr>
                    <td>
                        Category
                    </td>
                    <td>
                        <select name="Category" id="Category">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        Question
                    </td>
                    <td>
                        <input id="Question" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Answer
                    </td>
                    <td>
                        <!--<input id="Description" />-->
                        <textarea id="Answer" rows="5" cols="25" wrap="virtual"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <input type="submit" value="voeg toe" onclick="AddItems()" />
                    </td>
                </tr>
            </tbody>
        </table>
</div>